package cn.yitun.chat.yitunservercommonlib.crud.yitun;

import cn.yitun.chat.yitunservercommonlib.basebean.web.JwtUserDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Component
public class BaseController {

	@Resource
	private HttpServletRequest request;
	/**
	 * 日志对象
	 */
	protected Logger LOGGER = LoggerFactory.getLogger(getClass());
	/**
	 * 获取session参数
	 *
	 * @param attrName
	 * @return
	 */
	Object getSessionAttr(String attrName) {
		return request.getSession().getAttribute(attrName);
	}

	/**
	 * 设置Session参数
	 *
	 * @param attrName
	 * @param obj
	 */
	void setSessionAttr(String attrName, Object obj) {
		request.getSession().setAttribute(attrName, obj);
	}

	/**
	 * 新增基本参数封装
	 * @param baseDto
	 * @param jwtUserDto
	 */
	protected void setUserMsgSave(BaseDto baseDto , JwtUserDto jwtUserDto){
		setUserMsgUpdate(baseDto , jwtUserDto);
		baseDto.setCreateBy(jwtUserDto.getUserId());
		baseDto.setStatus(BaseInfo.STATUS_NORMAL);
	}

	/**
	 * 编辑基本参数封装
	 * @param baseDto
	 * @param jwtUserDto
	 */
	protected void setUserMsgUpdate(BaseDto baseDto , JwtUserDto jwtUserDto){
		baseDto.setUpdateBy(jwtUserDto.getUserId());
	}

	/**
	 * root用户且传入companyId时
	 * @param baseDto
	 * @param jwtUserDto
	 */
	protected void checkRootPage(BaseDto baseDto , JwtUserDto jwtUserDto){
		baseDto.setCurrentUserId(jwtUserDto.getUserId());
	}



}